package opl.ui.adapters;

import java.util.List;

import opl.entities.Team;
import opl.ui.R;
import opl.utilities.FileHelper;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TeamsAdapter extends ArrayAdapter<Team> {

	private static int teamsTemplate;
	private List<Team> lstTeams;
	private LayoutInflater lf;

	static {
		teamsTemplate = R.layout.team_template;
	}

	public TeamsAdapter(Context context, List<Team> objects) {
		super(context, teamsTemplate, objects);
		lstTeams = objects;
		lf = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView=lf.inflate(teamsTemplate, null);
		}

		TextView tvTeamName=(TextView) convertView.findViewById(R.id.tvTeamName);
		TextView tvCaptian=(TextView) convertView.findViewById(R.id.tvCaptian);
		ImageView imgTeamLogo=(ImageView)convertView.findViewById(R.id.imgTeamLogo);
		
		Team selectedTeam=lstTeams.get(position);
		
		tvTeamName.setText(selectedTeam.getName());
		tvCaptian.setText("Captian : "+ selectedTeam.getCaptian());
		imgTeamLogo.setImageDrawable(FileHelper.ReadFileFromResurceAsDrawable(selectedTeam.getName(), convertView.getContext()));
		
		return convertView;
	}

}
